//
//  BSNewFeatureCell.swift
//  mySwiftWeibo
//
//  Created by apple on 16/7/24.
//  Copyright © 2016年 itcast沈庆伟. All rights reserved.
//

import UIKit

class BSNewFeatureCell: UICollectionViewCell {
    
    ///cell要显示的图片
    var image: UIImage?{
        didSet{
            bkImageView.image=image
        }
    }
    
    //构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 公开方法
    func showButtons(isShow:Bool){
        shareButton.hidden = !isShow
        startButton.hidden = !isShow
    }
    
    ///设置UI元素
    private func setupUI(){
        self.contentView.addSubview(bkImageView)
        self.contentView.addSubview(startButton)
        self.contentView.addSubview(shareButton)
        
        //背景图约束
        bkImageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self.contentView)
        }
        
        //开始体验按钮
        startButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.contentView)
            make.bottom.equalTo(self.contentView).offset(-160)
        }
        
        //分享按钮
        shareButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.contentView)
            make.bottom.equalTo(startButton.snp_top).offset(-16)
        }
    }
    
    //MARK: - 按钮点击事件
    @objc private func shareButtonClick(){
        shareButton.selected = !shareButton.selected
    }
    
    @objc private func startButtonClick(){
        //print(__FUNCTION__)
        AppDelegate.switchRootViewController(BSMainTabBarController())
    }
    
    //MARK: - 懒加载
    //背景图片
    private lazy var bkImageView: UIImageView=UIImageView()
    
    //开始体验按钮
    private lazy var startButton: UIButton={
        let button=UIButton(type: UIButtonType.Custom)
        
        button.setTitle("开始体验", forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.addTarget(self, action: "startButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
    //分享按钮
    private lazy var shareButton: UIButton={
       let button=UIButton(type: UIButtonType.Custom)
        
        button.setTitle(" 分享给大家", forState: UIControlState.Normal)
        button.setImage(UIImage(named: "new_feature_share_false"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "new_feature_share_true"), forState: UIControlState.Selected)
        button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        
        button.addTarget(self, action: "shareButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
}
